/*
 * @Author: your name
 * @Date: 2021-09-30 20:27:44
 * @LastEditTime: 2021-09-30 21:49:25
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \luogu\1.6二分查找\P1024\equation.cpp
 */
#include "equation.h"
#include<iostream>

using namespace std;

Equation::Equation(double a, double b, double c, double d)
{
    this->m_a = a;
    this->m_b = b;
    this->m_c = c;
    this->m_d = d;
    this->NOT_FIND = -300;
}

Equation::~Equation()
{

}

double Equation::f(double x)
{
    return this->m_a*x*x*x + this->m_b*x*x + this->m_c*x + this->m_d;
}

double Equation::binarySearch(double leftnum, double rightnum)
{
    //左右指针
    double left = leftnum;
    double right = rightnum;
    
    while(right-left < 0.01){
        cout << "l:" << left << " r:" << right << endl;
        double mid = (left+right)/2;
        
        if(this->f(left) * this->f(mid) <= 0){
            //区间 [left,mid]
            right = mid;
        }else{
            //区间 (mid,right]
            left = mid+0.01;
        }
    }
    return left;
}

double Equation::getNOT_FIND()
{
    return this->NOT_FIND;
}